<?php include_partial('common/flashes') ?>
<form id="doctor-review-form" action="<?php echo url_for('/doctor-review/' . $doctorId) ?>" method="post">
    <?php echo $form->renderHiddenFields(false) ?>
    <div class="imperative">Have you any review comments about this doctor?</div>
    <?php include_partial("common/input_field", array("form" => $form, "field" => "comment", "show_label" => false)) ?>
    <div class="row">
        <ul>
            <li>
                <button id="submit-doctor-review" type="submit" class="blue-button-30">Submit</button>
                <input id="done-doctor-review" type="button" value="Done" class="brown-button-30">
            </li>
        </ul>
    </div>
    <div class="clear"></div>
</form>
<script type="text/javascript">
    //<![CDATA[
    $(document).ready(function(){
        // make an attempt to submit this form
        $('#submit-doctor-review').click(function() {
            $('#doctor-review-form').ajaxSubmit(function(data){                 
                if(hasForm(data))
                {         
                    $('#review-form').html(data);
                }
                else{ 
                    $('#my_doctor_review_id').val(data); 
                
                    // automatically load the doctor review form
                    $("#review-form").load('/doctor-review/<?php echo $doctorId ?>');
                }
            });
            return false;
        });
        
        $("#done-doctor-review").click(function(){
            // fetch the recently submitted doctor review and prepend it to the list
            
            if($("#my_doctor_review_id").val() != ""){
                $.get('/doctor-review-done/' + $("#my_doctor_review_id").val(), {}, function(data){                
                    $('#Member-reviews').prepend(data);
                }, 'html');
                
                // automatically load the doctor review form so we've a fresh form without any flash messages associated with it
                $("#review-form").load('/doctor-review/<?php echo $doctorId ?>');                
            }
            
            $.fn.colorbox.close();
        }); 
    });
    //]]>
</script>